
<%@ page import="org.gtesoreria.Consumo" %>
<%@ page import="org.gtesoreria.Rubro" %>
<%@ page import="org.gtesoreria.ConsumoController" %>
<%@ page import="org.gtesoreria.Adelanto" %>
<%@ page import="org.gtesoreria.Prestamo" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'consumo.label', default: 'Consumo')}" />
        <title>Descuentos por Mes</title>
    </head>
    <body>
        <div class="nav" style="display:none">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
        </div>
        <div class="body">
            <h1>Descuentos por Mes</h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div style="margin-top:10px;margin-bottom:10px;border:1px solid #999; padding:5px">
            	<g:form action="listConsumosPeriodo">
            		<table style="border:0px">
            		<tr>
            		<td style="padding-top:8px">Mes:</td>
            		<td><g:datePicker name="periodo" precision="month"></g:datePicker></td>
            		</tr>
            		<tr>
            		<td style="padding-top:8px">Rubro:</td>
            		<td><g:select name="rubro" from="${Consumo.listRubros()}" noSelection="${['null':'Todos...']}"></g:select></td>
            		</tr>
            		<tr>
            		<td>&nbsp</td>
            		<td style="text-align:right">
            			<g:submitButton name="listConsumosPeriodo" id="buscar" value="${message(code: 'default.button.buscar.label', default: 'Buscar')}" />
            		</td>
            		</tr>
            		</table>
            	</g:form>
            </div>
            <h1><g:formatDate date="${periodo}" format="MMMM yyyy"/></h1>
            <g:if test="${consumosSuper != null && consumosSuper.size > 0 }">
            	<g:render template='subListConsumosPeriodo' model="['periodo':periodo,'consumos':consumosSuper,'subTotal':subTotalSuper,rubro:Rubro.rubroSuper]"/>
            </g:if>
            <g:if test="${consumosAuto != null && consumosAuto.size > 0 }">
            	<g:render template='subListConsumosPeriodo' model="['periodo':periodo,'consumos':consumosAuto,'subTotal':subTotalAuto,rubro:Rubro.rubroAuto]"/>
            </g:if>
            <g:if test="${consumosInd != null && consumosInd.size > 0 }">
            	<g:render template='subListConsumosPeriodo' model="['periodo':periodo,'consumos':consumosInd,'subTotal':subTotalInd,rubro:Rubro.rubroInd]"/>
            </g:if>
            <g:if test="${consumosFarmacia != null && consumosFarmacia.size > 0 }">
            	<g:render template='subListConsumosPeriodo' model="['periodo':periodo,'consumos':consumosFarmacia,'subTotal':subTotalFarmacia,rubro:Rubro.rubroFarmacia]"/>
            </g:if>
            <g:if test="${consumosVarios != null && consumosVarios.size > 0 }">
            	<g:render template='subListConsumosPeriodo' model="['periodo':periodo,'consumos':consumosVarios,'subTotal':subTotalVarios,rubro:Rubro.rubroVarios]"/>
            </g:if>
	        <g:if test="${adelantos != null && adelantos.size > 0 }">
		        <div class="list">
				     <table>
				         <thead>
				             <tr>
				             	<th>${message(code: 'consumo.consumo.label', default: 'Legajo')} </th>
				             	
				             	 <th>${message(code: 'consumo.consumo.label', default: 'Apellido y Nombre')} </th>
				             	
				                 <th style="text-align:center; width:20em">Servicios Adelantos <g:formatDate date="${periodo}" format="MM-yyyy"/></th>
				             
				                 <th><g:message code="consumo.afiliado.label" default="Importe" /></th>
				             
				                 <th>${message(code: 'consumo.estado.label', default: 'Codigo de Desc')} </th>
				             </tr>
				         </thead>
				         <tbody>
				        		<g:each in="${adelantos}" status="l" var="adelantoInstance">
				        			<tr>
				        			<td>${fieldValue(bean: adelantoInstance, field: "afiliado.legajo")}</td>
				        			
				                <td>${fieldValue(bean: adelantoInstance, field: "afiliado.apellidoNombre")}</td>
				            
				                <td>&nbsp;</td>
				            
				                <td style="text-align:right"><g:formatNumber number="${adelantoInstance?.montoTotal}" type="number" minFractionDigits="2" maxFractionDigits ="2" roundingMode="HALF_UP" /></td>
				                
				                <td style="text-align:center">${Adelanto.CODIGO}</td>
				                </tr>
				        		</g:each>
								 </tr>
								  <td>&nbsp;</td><td>&nbsp;</td>
								  <td style="font-weight:bold">Total descuento:</td>
								  <td style="text-align:right"><g:formatNumber number="${subTotalAdelantos}" type="number" minFractionDigits="2" maxFractionDigits ="2" roundingMode="HALF_UP" /></td>
								  <td>&nbsp;</td>
								 </tr>
				
				        </tbody>
				    </table>
				</div>
			</g:if>
			<g:if test="${cuotas != null && cuotas.size > 0 }">
		        <div class="list">
				     <table>
				         <thead>
				             <tr>
				             	<th>${message(code: 'consumo.consumo.label', default: 'Legajo')} </th>
				             	
				             	 <th>${message(code: 'consumo.consumo.label', default: 'Apellido y Nombre')} </th>
				             	
				                 <th style="text-align:center; width:20em">Servicios Prestamos <g:formatDate date="${periodo}" format="MM-yyyy"/></th>
				             
				                 <th><g:message code="consumo.afiliado.label" default="Importe" /></th>
				             
				                 <th>${message(code: 'consumo.estado.label', default: 'Codigo de Desc')} </th>
				             </tr>
				         </thead>
				         <tbody>
				        		<g:each in="${cuotas}" status="l" var="cuotaInstance">
				        			<tr>
				        			<td>${fieldValue(bean: cuotaInstance, field: "credito.afiliado.legajo")}</td>
				        			
				                <td>${fieldValue(bean: cuotaInstance, field: "credito.afiliado.apellidoNombre")}</td>
				            
				                <td>&nbsp;</td>
				            
				                <td style="text-align:right"><g:formatNumber number="${cuotaInstance?.monto}" type="number" minFractionDigits="2" maxFractionDigits ="2" roundingMode="HALF_UP" /></td>
				                
				                <td style="text-align:center">${Prestamo.CODIGO}</td>
				                </tr>
				        		</g:each>
								 </tr>
								  <td>&nbsp;</td><td>&nbsp;</td>
								  <td style="font-weight:bold">Total descuento:</td>
								  <td style="text-align:right"><g:formatNumber number="${subTotalCuotas}" type="number" minFractionDigits="2" maxFractionDigits ="2" roundingMode="HALF_UP" /></td>
								  <td>&nbsp;</td>
								 </tr>
				
				        </tbody>
				    </table>
				</div>
			</g:if>
			<g:if test="${displayButtons }">
        <g:form action="exportarDescuentos">
                <g:hiddenField name="rubro" value="${rubro }"/>
                <g:hiddenField name="estado" value="${Adelanto.A_DESCUENTO }"/>
            	<input type="hidden" value="<g:formatDate date="${periodo}" format="MM/yyyy"/>" id="periodo" name="periodo"/>
           		<div align="right">
           		<g:actionSubmit value="Cerrar Periodo" action="cerrarPeriodo" class="myButtonBlue" controller="consumo" onclick="return confirm('Esta seguro de cerrar este periodo?')"/>
           		<g:actionSubmit value="Exportar Descuentos a Excel" action="exportarDescuentos" class="myButtonBlue" controller="consumo"/>
           		</div>
        </g:form>
        </g:if>
        </div>
        <div class="main-subcontent">

        <!-- Subcontent unit -->
	        <div class="subcontent-unit-border-blue">
	          <div class="round-border-topleft"></div><div class="round-border-topright"></div>
	          <h1 class="blue">Descuentos por Mes</h1>
	          <p style="text-align:left;font-style:normal">Elija mes, a&ntilde;o y rubro de descuento</p>
	          <p style="text-align:left;font-style:normal">Como resultado vera los descuentos realizados o a realizar a cada afiliado segun el rubro seleccionado</p>
	        </div>
	        
        </div>
    </body>
</html>
